<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script text="javascript">
        // 将数组中的  元素1  与  元素3 调换位置

        const arr = [3,2,1,4,5]
        let temp = arr[2]
        arr[2] = arr[0]
        arr[0] = temp
        document.write(arr)


        //使用冒泡排序（从大到小）：  [90,65,78,66,48,39,92,73]  使用数组解构的方法交换变量

        const arr = [90,65,78,66,48,39,92,73]
        console.log(arr.length);
        for(let i = 0; i < arr.length-1; i++){
            let temp
            for(let j = 0; j < arr.length-1; j++){
                if(arr[j] > arr[j+1]){
                temp = arr[j+1]
                arr[j+1] = arr[j]
                arr[j] = temp
            }
            }
        }
        document.write(arr)

        var text =
                    'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
        //将上述字符串去除标点空格后统计有多少个单词
        var temp = text.split("")
        var demo = ""
        console.log(temp);
        for(let i = 0; i < temp.length; i++){
            if(temp[i] == "," || temp[i] == "."){
                temp.splice(i,1)
            }
            demo += temp[i]
             
        }
        demo = demo.split(" ")
        console.log(demo.length);
        console.log(temp);
        console.log(demo);
       

        // const arr = [87,85,74,70,65,59,43]
        // 1.移除第一个元素87，并在开头添加 元素86
 
        // arr.shift
        // arr.unshift(86)

        arr.splice(0,1,86)
        document.write(arr+"<br>")
        // 2.移除最后一个元素43， 并在末尾添加1

        // arr.pop
        // arr.push(1)

        arr.splice(arr.length-1,1,1)
        document.write(arr+"<br>")
        // 3.在 70 65 之间插入 元素 68
        var i = arr.indexOf(70)
        var j = arr.indexOf(65)
        arr.splice(i>j?i:j,0,68)
        document.write(arr+"<br>")
        // 4.删除元素65
        var i = arr.indexOf(65)
        arr.splice(i,1)
        document.write(arr+"<br>")
        // 5.使用map返回一个新的数组new_arr，要求新数组new_arr比原来数组大2
        const new_arr = arr.map(
            x=>{
                return x + 2
            }
        )
        // document.write(new_arr+"<br>")
        // 6.筛选数组new_arr返回new_arr1,要求new_arr1: 能被2整除  
        var new_arr1 = []
        var j = 0
        for(let i = 0;i < new_arr.length; i++){
            if(new_arr[i] % 2 == 0){
                new_arr1[j] = new_arr[i]
                j++
            }
        }
        document.write(new_arr1)
        


    </script>
</body>
</html>